angular.module('myApp.services', [])
    .service('LoginService', function ($q, $http) {
        return {
            loginUser: function (name, pw) {
                var deferred = $q.defer();
                var promise = deferred.promise;
                //ajax请求
                $http.post("http://www.baidu.com")
                    .success(function (response) {
                      //请求成功
                    });

                promise.success = function (fn) {
                    promise.then(fn);
                    return promise;
                }
                promise.error = function (fn) {
                    promise.then(null, fn);
                    return promise;
                }
                return promise;
            },


        }
    });
